#!/bin/sh
#
# description: Starts and stops the vsftpd daemon
#
export mos=/usr/local/etc/mos
start() {
	# waiting valid IP address
	while [ -z "$(ifconfig | sed -n '/127.0.0.1/d;/192.168.0.9/d;s/^ *inet addr:\([^ ]*\).*$/\1/p' )" ] ; do
	  sleep 5
	done

	echo "Starting mediatomb service..."
	export MEDIATOMB_DATADIR="$mos/mediatomb/share/mediatomb"
	export MEDIATOMB_MAGIC_FILE="$mos/mediatomb/share/file/magic"
	$mos/mediatomb/bin/mediatomb -m $mos/mediatomb -f config -d -l /tmp/mediatomb.log
	return 0;
}	

stop() {
	echo "Shutting down mediatomb services..."
	killall -9 mediatomb
	return 0;
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  status)
	stat=`ps -a | grep mediatomb | sed '/grep/d/status/d'`
	if [ -z "$stat" ] ; then
		echo "mediatomb is stopped"
	else
		echo "mediatomb is running"
	fi
	;;
  enable | disable)
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status|enable|disable}"
esac

exit $?
